package com.hck.app.service;

import com.hck.api.model.DoctorLoginRequestDTO;
import com.hck.api.model.DoctorLoginResponseDTO;
import com.hck.domain.doctor.model.entity.DoctorEntity;
import com.hck.domain.doctor.model.valobj.LoginRequest;
import com.hck.domain.doctor.model.valobj.LoginResult;
import com.hck.domain.doctor.service.DoctorDomainService;
import com.hck.domain.doctor.service.IDoctorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * DoctorService class description here.
 *
 * @author 黄朝看
 * @date 2025/7/2
 */
@Service
public class DoctorService implements IDoctorService {
    @Resource
    private DoctorDomainService domainService;

    @Override
    public DoctorLoginResponseDTO login(DoctorLoginRequestDTO requestDTO) {
        LoginRequest loginRequest = new LoginRequest();

        loginRequest.setLoginName(requestDTO.getLoginName());
        loginRequest.setPassword(requestDTO.getPassword());

        LoginResult loginResult =  domainService.login(loginRequest);

        DoctorLoginResponseDTO doctorLoginResponseDTO = new DoctorLoginResponseDTO();
        doctorLoginResponseDTO.setSuccess(loginResult.isSuccess());
        doctorLoginResponseDTO.setErrorMessage(loginResult.getErrorMessage());

        if(loginResult.isSuccess()){
            doctorLoginResponseDTO.setLoginName(loginResult.getLoginName());
            doctorLoginResponseDTO.setDoctorId(loginResult.getDoctorId());
            doctorLoginResponseDTO.setRealName(loginResult.getRealName());
        }
        return doctorLoginResponseDTO;
    }

    @Override
    public DoctorEntity getDoctorInfo(Long doctorId) {
        return domainService.getDoctorInfo(doctorId);
    }

    @Override
    public List<DoctorEntity> getAllDoctors() {
        return domainService.getAllDoctors();
    }
}
